<template>
  <div class="wrapper">
    <v-head></v-head>
    <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      background-color="#324157"
      text-color="#bfcbd9"
      active-text-color="#20a0ff"
      unique-opened
      router
    >
    <template v-for="(item,index) in this.routes">
      <template v-if="!item.hidden">
      <el-submenu :key="index" :index="index+''">
        <template slot="title">
          <i :class="item.iconCls" style="color: #20a0ff;width: 14px;"></i>
          <span slot="title">{{item.name}}</span>
        </template>
        <el-menu-item width="180px"
                      style="padding-left: 30px;padding-right:0px;margin-left: 0px;width: 170px;text-align: left"
                      v-for="child in item.children"
                      :index="child.path"
                      :key="child.path">{{child.name}}
        </el-menu-item>
      </el-submenu>
      </template>
    </template>
    </el-menu>
  </div>
    <div class="content-box" :class="{'content-collapse':collapse}">
      <!-- <v-tags></v-tags> -->
      <div class="content">
        <transition name="move" mode="out-in">
          <keep-alive :include="tagsList">
            <router-view></router-view>
          </keep-alive>
        </transition>
      </div>
    </div>
  </div>
</template>


<script>
import vHead from "./Header.vue";
import vSidebar from "./Sidebar.vue";
import vTags from "./Tags.vue";
import bus from "./bus";

export default {
  data() {
    return {
      tagsList: [],
      collapse: false,
      load:true
    };
  },
  computed:{
    routes(){
        return this.$store.state.routes
    },
    onRoutes() {
      return this.$route.path.replace("/", "");
    }
  },
  components: {
    vHead,
    vSidebar,
    vTags,
  },
  methods:{
     reloads() {
       if(this.load == true){
         location.reload();
         this.load = false;
       }
    }
  },
  created() {
    // this.reloads();
    bus.$on("collapse", msg => {
      this.collapse = msg;
    })
    bus.$on("tags", msg => {
      let arr = [];
      for (let i = 0, len = msg.length; i < len; i++) {
        msg[i].name && arr.push(msg[i].name);
      }
      this.tagsList = arr;
    })
  }
};
</script>

<style>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}


</style>
